import { nanoid } from 'nanoid'
import { ElMessage } from 'element-plus'
import localCache from '../../../utils/cache'
import ITaskData from '../types/ITaskData'
import { UNDERWAYTASKID } from "../constant/taskId"

/**
 * 添加一个任务
 * @param title 任务标题
 * @param taskData 任务数据数组
 */
export const addTask = (title: string, taskData: ITaskData): void => {
  //空格，tab返回
  if(title.trim() == ""){
    ElMessage({
    showClose: true,
    message: '还没有输入内容',
    type: 'info',
  })
    return
  }
  
  const id = nanoid()

  taskData.underwayTaskData.push({
    id,
    title: title
  })
  localCache.setCache(UNDERWAYTASKID+id,title)

  ElMessage({
    showClose: true,
    message: '新增任务成功',
    type: 'success',
  })
}